/**
 * 
 */
package cn.wangsy.zhidao.p20170708;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.apache.commons.io.IOUtils;

/**
 * @author wangsy
 * @date 2017年7月8日下午3:07:06
 */
public class ImageDownloader {

	public static void main(String[]args) throws IOException{
		
		URL url = new URL("http://img4.duitang.com/uploads/item/201504/25/20150425H4628_NHPX8.jpeg");
		InputStream inputStream = url.openStream();
		
		/*int length = inputStream.available();
		System.out.println(length);
		byte[]data = new byte[length];
		inputStream.read(data);
		inputStream.close();
		
		FileOutputStream outputStream = new FileOutputStream("1.jpg");
		outputStream.write(data);
		outputStream.close();*/
		
		FileOutputStream outputStream = new FileOutputStream("1.jpg");
		int ch;
		while((ch = inputStream.read()) != -1){
			outputStream.write(ch);
		}
		outputStream.close();
		
		/*byte[]data = IOUtils.toByteArray(url);
		//byte[]data = IOUtils.toByteArray(inputStream);
		FileOutputStream outputStream = new FileOutputStream("2.jpg");
		outputStream.write(data);
		outputStream.close();*/
		
	}
	
}
